/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-01-25
 * Time: 22:22
 */
public class test1 {
    /*
    LeetCode 917  仅仅反转字母
     */

    public String reverseOnlyLetters(String s) {
        int n = s.length();
        char[] arr = s.toCharArray();
        int left = 0;
        int right = n-1;
        while(left<right){
            while(left<right && !Character.isLetter(s.charAt(left))){
                left++;
            }
            while(left<right && !Character.isLetter(s.charAt(right))){
                right--;
            }
            swap(arr,left,right);
            left++;
            right--;
        }
        return new String(arr);
    }

    public void swap(char[] arr,int left,int right){
        char tmp = arr[left];
        arr[left] = arr[right];
        arr[right] = tmp;
    }
}
